<!doctype html>
<html lang="zh-CN">
<head>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>JDBCTemplate总结 | Jeremy Sze的博客</title>
    <meta property="og:title" content="JDBCTemplate总结 - Jeremy Sze的博客">
    <meta property="og:type" content="article">
        
    <meta property="article:published_time" content='2020-09-11T08:36:54&#43;08:00'>
        
        
    <meta property="article:modified_time" content='2020-09-11T08:36:54&#43;08:00'>
        
    <meta name="Keywords" content="java,博客">
    <meta name="description" content="JDBCTemplate总结">
        
    <meta name="author" content="Jeremy Sze">
    <meta property="og:url" content="https://laoer123.gitee.io/laoer123/post/JdbcTemplate%E6%80%BB%E7%BB%93/">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">

    <link rel="stylesheet" href='/laoer123/css/normalize.css'>
    <link rel="stylesheet" href='/laoer123/css/style.css'>
    <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

    
    <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
    <script>
    (adsbygoogle = window.adsbygoogle || []).push({
        google_ad_client: "ca-pub-4031353640611810",
        enable_page_level_ads: true
    });
    </script>
    


    
    
        <link rel="stylesheet" href='/laoer123/css/douban.css'>
    
        <link rel="stylesheet" href='/laoer123/css/other.css'>
    
</head>


<body>
    <header id="header" class="clearfix">
    <div class="container">
        <div class="col-group">
            <div class="site-name ">
                
                    <a id="logo" href="https://laoer123.gitee.io/laoer123">
                        Jeremy Sze的博客
                    </a>
                
                <p class="description">专注于Java、JavaScript、软件开发、web开发、分布式，微服务系统开发</p>
            </div>
            <div>
                <nav id="nav-menu" class="clearfix">
                    <a class="current" href="https://laoer123.gitee.io/laoer123">首页</a>
                    
                    <a  href="https://laoer123.gitee.io/laoer123/about/" title="关于">关于</a>
                    
                </nav>
            </div>
        </div>
    </div>
</header>

    <div id="body">
        <div class="container">
            <div class="col-group">

                <div class="col-8" id="main">
                    
<div class="res-cons">
    <style type="text/css">
    .post-toc {
        position: fixed;
        width: 200px;
        margin-left: -210px;
        padding: 5px 10px;
        font-family: Athelas, STHeiti, Microsoft Yahei, serif;
        font-size: 12px;
        border: 1px solid rgba(0, 0, 0, .07);
        border-radius: 5px;
        background-color: rgba(255, 255, 255, 0.98);
        background-clip: padding-box;
        -webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        box-shadow: 1px 1px 2px rgba(0, 0, 0, .125);
        word-wrap: break-word;
        white-space: nowrap;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
        z-index: 999;
        cursor: pointer;
        max-height: 70%;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .post-toc .post-toc-title {
        width: 100%;
        margin: 0 auto;
        font-size: 20px;
        font-weight: 400;
        text-transform: uppercase;
        text-align: center;
    }

    .post-toc .post-toc-content {
        font-size: 15px;
    }

    .post-toc .post-toc-content>nav>ul {
        margin: 10px 0;
    }

    .post-toc .post-toc-content ul {
        padding-left: 20px;
        list-style: square;
        margin: 0.5em;
        line-height: 1.8em;
    }

    .post-toc .post-toc-content ul ul {
        padding-left: 15px;
        display: none;
    }

    @media print,
    screen and (max-width:1057px) {
        .post-toc {
            display: none;
        }
    }
</style>
<div class="post-toc" style="position: absolute; top: 188px;">
    <h2 class="post-toc-title">文章目录</h2>
    <div class="post-toc-content">
        <nav id="TableOfContents">
  <ul>
    <li><a href="#jdbctemplate概念">JdbcTemplate概念</a></li>
    <li><a href="#jdbctemplate使用过程">JdbcTemplate使用过程</a>
      <ul>
        <li><a href="#druid基于配置文件实现连接池">Druid基于配置文件实现连接池</a></li>
      </ul>
    </li>
    <li><a href="#使用步骤">使用步骤</a></li>
    <li><a href="#创建表">创建表</a></li>
    <li><a href="#jdbctemplate实现增删改">JdbcTemplate实现增删改</a></li>
    <li><a href="#使用步骤-1">使用步骤</a></li>
    <li><a href="#增删改查代码">增删改查代码</a></li>
    <li><a href="#jdbctemplate实现查询">JdbcTemplate实现查询</a>
      <ul>
        <li><a href="#queryforint返回一个整数">queryForInt返回一个整数</a></li>
        <li><a href="#返回一个long">返回一个long</a></li>
        <li><a href="#返回一个字符串">返回一个字符串</a></li>
        <li><a href="#queryformap返回一个map集合对象">queryForMap返回一个Map集合对象</a></li>
        <li><a href="#queryforlist返回一个list集合对象集合对象存储map类型数据">queryForList返回一个List集合对象，集合对象存储Map类型数据</a></li>
      </ul>
    </li>
    <li><a href="#查询一个对象">查询一个对象</a>
      <ul>
        <li><a href="#query使用rowmapper做映射返回对象">query使用RowMapper做映射返回对象</a></li>
        <li><a href="#query使用beanpropertyrowmapper做映射返回对象">query使用BeanPropertyRowMapper做映射返回对象</a></li>
        <li><a href="#查询数据自定义封装返回固定格式给前端">查询数据，自定义封装返回固定格式给前端</a></li>
      </ul>
    </li>
    <li><a href="#jdbctemplate原理">JdbcTemplate原理</a>
      <ul>
        <li><a href="#11模拟jdbctemplate">1.1	模拟JdbcTemplate</a></li>
        <li><a href="#12步骤分析">1.2	步骤分析</a></li>
      </ul>
    </li>
  </ul>
</nav>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var postToc = $(".post-toc");
        if (postToc.length) {
            var leftPos = $("#main").offset().left;
            if(leftPos<220){
                postToc.css({"width":leftPos-10,"margin-left":(0-leftPos)})
            }

            var t = postToc.offset().top - 20,
                a = {
                    start: {
                        position: "absolute",
                        top: t
                    },
                    process: {
                        position: "fixed",
                        top: 20
                    },
                };
            $(window).scroll(function () {
                var e = $(window).scrollTop();
                e < t ? postToc.css(a.start) : postToc.css(a.process)
            })
        }
    })
</script>
    <article class="post">
        <header>
            <h1 class="post-title">JDBCTemplate总结</h1>
        </header>
        <date class="post-meta meta-date">
            2020年9月11日
        </date>
        
        <div class="post-meta">
            <span>|</span>
            
            <span class="meta-category"><a href='https://laoer123.gitee.io/categories/%E6%95%B0%E6%8D%AE%E5%BA%93'>数据库</a></span>
            
        </div>
        
        
        <div class="post-meta">
            <span id="busuanzi_container_page_pv">|<span id="busuanzi_value_page_pv"></span><span>
                    阅读</span></span>
        </div>
        
        
        <div class="post-content">
            <h2 id="jdbctemplate概念">JdbcTemplate概念</h2>
<p>  JDBC已经能够满足大部分用户最基本的需求，但是在使用JDBC时，必须自己来管理数据库资源如：获取
PreparedStatement，设置SQL语句参数，关闭连接等步骤。JdbcTemplate就是Spring对JDBC的封装，目的是使
JDBC更加易于使用。JdbcTemplate是Spring的一部分。 JdbcTemplate处理了资源的建立和释放。他帮助我们避
免一些常见的错误，比如忘了总要关闭连接。他运行核心的JDBC工作流，如Statement的建立和执行，而我们只需
要提供SQL语句和提取结果。<br>
Spring源码地址： <a href="https://github.com/spring-projects/spring-framework">https://github.com/spring-projects/spring-framework</a> <br>
在JdbcTemplate中执行SQL语句的方法大致分为3类：<br>
$\color{red}{1. execute ：可以执行所有SQL语句，一般用于执行DDL语句。建表  }$<br>
$\color{red}{2. update ：用于执行 INSERT 、 UPDATE 、 DELETE 等DML语句。}$<br>
$\color{red}{3. queryXxx ：用于DQL数据查询语句 }$</p>
<h2 id="jdbctemplate使用过程">JdbcTemplate使用过程</h2>
<h3 id="druid基于配置文件实现连接池">Druid基于配置文件实现连接池</h3>
<p>org.springframework.jdbc.core.JdbcTemplate 类方便执行SQL语句</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#900;font-weight:bold">JdbcTemplate</span><span style="color:#000;font-weight:bold">(</span>DataSource dataSource<span style="color:#000;font-weight:bold">)</span>
<span style="color:#998;font-style:italic">//创建JdbcTemplate对象，方便执行SQL语句
</span><span style="color:#998;font-style:italic"></span>

<span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">execute</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">final</span> String sql<span style="color:#000;font-weight:bold">)</span>
<span style="color:#998;font-style:italic">//execute可以执行所有SQL语句，因为没有返回值，一般用于执行DML语句
</span></code></pre></td></tr></table>
</div>
</div><h2 id="使用步骤">使用步骤</h2>
<ol>
<li>准备DruidDataSource连接池</li>
<li>导入依赖的jar包</li>
</ol>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-txt" data-lang="txt">	spring-beans-4.1.2.RELEASE.jar
	spring-core-4.1.2.RELEASE.jar
	spring-jdbc-4.1.2.RELEASE.jar
	spring-tx-4.1.2.RELEASE.jar
	com.springsource.org.apache.commons.logging-1.1.1.jar
</code></pre></td></tr></table>
</div>
</div><ol start="3">
<li>创建 JdbcTemplate 对象，传入 Druid 连接池</li>
<li>调用 execute 、 update 、 queryXxx 等方法</li>
</ol>
<h2 id="创建表">创建表</h2>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">Demo04</span> <span style="color:#000;font-weight:bold">{</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">main</span><span style="color:#000;font-weight:bold">(</span>String<span style="color:#000;font-weight:bold">[]</span> args<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
<span style="color:#998;font-style:italic">// 创建表的SQL语句
</span><span style="color:#998;font-style:italic"></span>String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;CREATE TABLE product(&#34;</span>
<span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;pid INT PRIMARY KEY AUTO_INCREMENT,&#34;</span>
<span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;pname VARCHAR(20),&#34;</span>
<span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;price DOUBLE&#34;</span>
<span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;);&#34;</span><span style="color:#000;font-weight:bold">;</span>
JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">execute</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="jdbctemplate实现增删改">JdbcTemplate实现增删改</h2>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">int</span> <span style="color:#900;font-weight:bold">update</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">final</span> String sql<span style="color:#000;font-weight:bold">)</span>
<span style="color:#998;font-style:italic">//用于执行`INSERT`、`UPDATE`、`DELETE`等DML语句。
</span></code></pre></td></tr></table>
</div>
</div><h2 id="使用步骤-1">使用步骤</h2>
<ol>
<li>创建JdbcTemplate对象</li>
<li>编写SQL语句</li>
<li>使用JdbcTemplate对象的update方法进行增删改</li>
</ol>
<h2 id="增删改查代码">增删改查代码</h2>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">main</span><span style="color:#000;font-weight:bold">(</span>String<span style="color:#000;font-weight:bold">[]</span> args<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
<span style="color:#998;font-style:italic">// test01();
</span><span style="color:#998;font-style:italic">// test02();
</span><span style="color:#998;font-style:italic">// test03();
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">}</span>
<span style="color:#998;font-style:italic">// JDBCTemplate添加数据
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test01</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
		JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
		String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;INSERT INTO product VALUES (NULL, ?, ?);&#34;</span><span style="color:#000;font-weight:bold">;</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone3GS&#34;</span><span style="color:#000;font-weight:bold">,</span> 3333<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone4&#34;</span><span style="color:#000;font-weight:bold">,</span> 5000<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone4S&#34;</span><span style="color:#000;font-weight:bold">,</span> 5001<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone5&#34;</span><span style="color:#000;font-weight:bold">,</span> 5555<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone5C&#34;</span><span style="color:#000;font-weight:bold">,</span> 3888<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone5S&#34;</span><span style="color:#000;font-weight:bold">,</span> 5666<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone6&#34;</span><span style="color:#000;font-weight:bold">,</span> 6666<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone6S&#34;</span><span style="color:#000;font-weight:bold">,</span> 7000<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhone6SP&#34;</span><span style="color:#000;font-weight:bold">,</span> 7777<span style="color:#000;font-weight:bold">);</span>
		jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;iPhoneX&#34;</span><span style="color:#000;font-weight:bold">,</span> 8888<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>

<span style="color:#998;font-style:italic">// JDBCTemplate修改数据
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test02</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
		JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
		String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;UPDATE product SET pname=?, price=? WHERE pid=?;&#34;</span><span style="color:#000;font-weight:bold">;</span>
		<span style="color:#458;font-weight:bold">int</span> i <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#d14">&#34;XVIII&#34;</span><span style="color:#000;font-weight:bold">,</span> 18888<span style="color:#000;font-weight:bold">,</span> 10<span style="color:#000;font-weight:bold">);</span>
		System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;影响的行数: &#34;</span> <span style="color:#000;font-weight:bold">+</span> i<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>

<span style="color:#998;font-style:italic">// JDBCTemplate删除数据
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test03</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
		JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
		String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;DELETE FROM product WHERE pid=?;&#34;</span><span style="color:#000;font-weight:bold">;</span>
		<span style="color:#458;font-weight:bold">int</span> i <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">update</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> 7<span style="color:#000;font-weight:bold">);</span>
		System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;影响的行数: &#34;</span> <span style="color:#000;font-weight:bold">+</span> i<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>$\color{red}{JdbcTemplate的 update 方法用于执行DML语句。同时还可以在SQL语句中使用？占位，在update方法的Object&hellip; args 可变参数中传入对应的参数。}$</p>
<h2 id="jdbctemplate实现查询">JdbcTemplate实现查询</h2>
<h3 id="queryforint返回一个整数">queryForInt返回一个整数</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">int</span> <span style="color:#900;font-weight:bold">queryForInt</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">)</span>
<span style="color:#998;font-style:italic">//执行查询语句，返回一个int类型的值。
</span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">// queryForInt返回一个整数
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test01</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
<span style="color:#998;font-style:italic">// String sql = &#34;SELECT COUNT(*) FROM product;&#34;;
</span><span style="color:#998;font-style:italic"></span>String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;SELECT pid FROM product WHERE price=18888;&#34;</span><span style="color:#000;font-weight:bold">;</span>
JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
<span style="color:#458;font-weight:bold">int</span> forInt <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">queryForInt</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">);</span>
System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>forInt<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="返回一个long">返回一个long</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">// queryForLong返回一个long类型整数
</span><span style="color:#998;font-style:italic"></span> <span style="color:#000;font-weight:bold">public</span> <span style="color:#458;font-weight:bold">long</span> <span style="color:#900;font-weight:bold">queryForLong</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">)</span>
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">// queryForLong 返回一个long类型整数
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test02</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
		String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;SELECT COUNT(*) FROM product;&#34;</span><span style="color:#000;font-weight:bold">;</span>
		<span style="color:#998;font-style:italic">// String sql = &#34;SELECT pid FROM product WHERE price=18888;&#34;;
</span><span style="color:#998;font-style:italic"></span>		JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
		<span style="color:#458;font-weight:bold">long</span> forLong <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">queryForLong</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">);</span>
		System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>forLong<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="返回一个字符串">返回一个字符串</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#998;font-style:italic">//queryForObject返回String
</span><span style="color:#998;font-style:italic"></span> <span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> T <span style="color:#900;font-weight:bold">queryForObject</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">,</span> Class<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> requiredType<span style="color:#000;font-weight:bold">)</span>
<span style="color:#998;font-style:italic">//执行查询语句，返回一个指定类型的数据。
</span></code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test03</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
		String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;SELECT pname FROM product WHERE price=7777;&#34;</span><span style="color:#000;font-weight:bold">;</span>
		JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
		String str <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">queryForObject</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> String<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">class</span><span style="color:#000;font-weight:bold">);</span>
		System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>str<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="queryformap返回一个map集合对象">queryForMap返回一个Map集合对象</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">queryForMap</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">)</span>
执行查询语句<span style="color:#a61717;background-color:#e3d2d2">，</span>将一条记录放到一个Map中<span style="color:#a61717;background-color:#e3d2d2">。</span>
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test04</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;SELECT * FROM product WHERE pid=?;&#34;</span><span style="color:#000;font-weight:bold">;</span>
JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> map <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">queryForMap</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> 6<span style="color:#000;font-weight:bold">);</span>
System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>map<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="queryforlist返回一个list集合对象集合对象存储map类型数据">queryForList返回一个List集合对象，集合对象存储Map类型数据</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> List<span style="color:#000;font-weight:bold">&lt;</span>Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;&gt;</span> <span style="color:#900;font-weight:bold">queryForList</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">)</span>
执行查询语句<span style="color:#a61717;background-color:#e3d2d2">，</span>返回一个List集合<span style="color:#a61717;background-color:#e3d2d2">，</span>List中存放的是Map类型的数据<span style="color:#a61717;background-color:#e3d2d2">。</span>
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">8
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test05</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;SELECT * FROM product WHERE pid&lt;?;&#34;</span><span style="color:#000;font-weight:bold">;</span>
JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
List<span style="color:#000;font-weight:bold">&lt;</span>Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;&gt;</span> list <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">queryForList</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> 8<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">for</span> <span style="color:#000;font-weight:bold">(</span>Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> map <span style="color:#000;font-weight:bold">:</span> list<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>map<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h2 id="查询一个对象">查询一个对象</h2>
<h3 id="query使用rowmapper做映射返回对象">query使用RowMapper做映射返回对象</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> List<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">query</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">,</span> RowMapper<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> rowMapper<span style="color:#000;font-weight:bold">)</span>
执行查询语句<span style="color:#a61717;background-color:#e3d2d2">，</span>返回一个List集合<span style="color:#a61717;background-color:#e3d2d2">，</span>List中存放的是RowMapper指定类型的数据<span style="color:#a61717;background-color:#e3d2d2">。</span>
</code></pre></td></tr></table>
</div>
</div><ol>
<li>定义Product类</li>
<li>创建JdbcTemplate对象</li>
<li>编写查询的SQL语句</li>
<li>使用JdbcTemplate对象的query方法，并传入RowMapper匿名内部类</li>
<li>在匿名内部类中将结果集中的一行记录转成一个Product对象</li>
</ol>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">// query使用rowMap做映射返回一个对象
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test06</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
		JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
			<span style="color:#998;font-style:italic">// 查询数据的SQL语句
</span><span style="color:#998;font-style:italic"></span>			String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;SELECT * FROM product;&#34;</span><span style="color:#000;font-weight:bold">;</span>
			List<span style="color:#000;font-weight:bold">&lt;</span>Product<span style="color:#000;font-weight:bold">&gt;</span> query <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">query</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#000;font-weight:bold">new</span> RowMapper<span style="color:#000;font-weight:bold">&lt;</span>Product<span style="color:#000;font-weight:bold">&gt;()</span> <span style="color:#000;font-weight:bold">{</span>
			<span style="color:#3c5d5d;font-weight:bold">@Override</span>
			<span style="color:#000;font-weight:bold">public</span> Product <span style="color:#900;font-weight:bold">mapRow</span><span style="color:#000;font-weight:bold">(</span>ResultSet arg0<span style="color:#000;font-weight:bold">,</span> <span style="color:#458;font-weight:bold">int</span> arg1<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">throws</span> SQLException <span style="color:#000;font-weight:bold">{</span>
			Product p <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> Product<span style="color:#000;font-weight:bold">();</span>
			p<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setPid</span><span style="color:#000;font-weight:bold">(</span>arg0<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getInt</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;pid&#34;</span><span style="color:#000;font-weight:bold">));</span>
			p<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setPname</span><span style="color:#000;font-weight:bold">(</span>arg0<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;pname&#34;</span><span style="color:#000;font-weight:bold">));</span>
			p<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setPrice</span><span style="color:#000;font-weight:bold">(</span>arg0<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDouble</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;price&#34;</span><span style="color:#000;font-weight:bold">));</span>
			<span style="color:#000;font-weight:bold">return</span> p<span style="color:#000;font-weight:bold">;</span>
			<span style="color:#000;font-weight:bold">}</span>
			<span style="color:#000;font-weight:bold">});</span>
			<span style="color:#000;font-weight:bold">for</span> <span style="color:#000;font-weight:bold">(</span>Product product <span style="color:#000;font-weight:bold">:</span> query<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
			System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>product<span style="color:#000;font-weight:bold">);</span>
<span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="query使用beanpropertyrowmapper做映射返回对象">query使用BeanPropertyRowMapper做映射返回对象</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> List<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">query</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">,</span> RowMapper<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> rowMapper<span style="color:#000;font-weight:bold">)</span>
执行查询语句<span style="color:#a61717;background-color:#e3d2d2">，</span>返回一个List集合<span style="color:#a61717;background-color:#e3d2d2">，</span>List中存放的是RowMapper指定类型的数据<span style="color:#a61717;background-color:#e3d2d2">。</span>

<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">BeanPropertyRowMapper</span><span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#000;font-weight:bold">implements</span> RowMapper<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span>
BeanPropertyRowMapper类实现了RowMapper接口
</code></pre></td></tr></table>
</div>
</div><ol>
<li>定义Product类</li>
<li>创建JdbcTemplate对象</li>
<li>编写查询的SQL语句</li>
<li>使用JdbcTemplate对象的query方法，并传入BeanPropertyRowMapper对象</li>
</ol>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">// query使用BeanPropertyRowMapper做映射返回对象
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">test07</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">throws</span> Exception <span style="color:#000;font-weight:bold">{</span>
		JdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> JdbcTemplate<span style="color:#000;font-weight:bold">(</span>JdbcUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
		<span style="color:#998;font-style:italic">// 查询数据的SQL语句
</span><span style="color:#998;font-style:italic"></span>		String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;SELECT * FROM product;&#34;</span><span style="color:#000;font-weight:bold">;</span>
		List<span style="color:#000;font-weight:bold">&lt;</span>Product<span style="color:#000;font-weight:bold">&gt;</span> list <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">query</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#000;font-weight:bold">new</span> BeanPropertyRowMapper<span style="color:#000;font-weight:bold">&lt;&gt;</span>
		<span style="color:#000;font-weight:bold">(</span>Product<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">class</span><span style="color:#000;font-weight:bold">));</span>
		<span style="color:#000;font-weight:bold">for</span> <span style="color:#000;font-weight:bold">(</span>Product product <span style="color:#000;font-weight:bold">:</span> list<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
		System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>product<span style="color:#000;font-weight:bold">);</span>
		<span style="color:#000;font-weight:bold">}</span>
		<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><h3 id="查询数据自定义封装返回固定格式给前端">查询数据，自定义封装返回固定格式给前端</h3>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">62
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">63
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">64
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">65
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">66
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">67
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">68
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">69
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">70
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">71
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">72
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">73
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">74
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">75
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">76
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">77
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">78
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">79
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">80
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">81
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">82
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">83
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">84
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">85
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">86
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">87
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">88
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">89
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">90
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">91
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">92
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">93
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">94
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">95
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#000;font-weight:bold">public</span> HashMap<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">queryAll</span><span style="color:#000;font-weight:bold">(</span>JSONObject jsonObject<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        Integer page <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getInteger</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;page&#34;</span><span style="color:#000;font-weight:bold">);</span>
        Integer size <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getInteger</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;size&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#998;font-style:italic">// to_char(roj.social_time,&#39;yyyy-MM-dd HH:mm:ss&#39;) social_time
</span><span style="color:#998;font-style:italic"></span>        StringBuffer querySQL <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> StringBuffer<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;select&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.id,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.jn29_001b,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.jn29_001a,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.jn29_002,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.jn29_003,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.jn29_004,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.jn29_005,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.bizstatus,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       to_char(t.createdate,&#39;yyyy-MM-dd HH:mm:ss&#39;) createdate,&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34;       t.jn29_006 from jn29 t where  t.bizstatus=&#39;1&#39;  &#34;</span><span style="color:#000;font-weight:bold">);</span>
        HashMap<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> gridData <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> HashMap<span style="color:#000;font-weight:bold">&lt;&gt;();</span>
        List<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">&gt;</span> params <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> ArrayList<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">&gt;();</span>

        <span style="color:#998;font-style:italic">//工种名称
</span><span style="color:#998;font-style:italic"></span>        String jn29_002 <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_002&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>StringUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">isNotBlank</span><span style="color:#000;font-weight:bold">(</span>jn29_002<span style="color:#000;font-weight:bold">))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and t.jn29_002  like ?  &#34;</span><span style="color:#000;font-weight:bold">);</span>
            params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">add</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;%&#34;</span><span style="color:#000;font-weight:bold">+</span>jn29_002<span style="color:#000;font-weight:bold">+</span><span style="color:#d14">&#34;%&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#998;font-style:italic">//培训类别编码
</span><span style="color:#998;font-style:italic"></span>        String jn29_001b <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_001b&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>StringUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">isNotBlank</span><span style="color:#000;font-weight:bold">(</span>jn29_001b<span style="color:#000;font-weight:bold">))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and t.jn29_001b  = ?  &#34;</span><span style="color:#000;font-weight:bold">);</span>
            params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">add</span><span style="color:#000;font-weight:bold">(</span>jn29_001b<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#998;font-style:italic">//有效性
</span><span style="color:#998;font-style:italic"></span>        String bizstatus <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;bizstatus&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>StringUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">isNotBlank</span><span style="color:#000;font-weight:bold">(</span>bizstatus<span style="color:#000;font-weight:bold">))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and t.bizstatus  = ?  &#34;</span><span style="color:#000;font-weight:bold">);</span>
            params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">add</span><span style="color:#000;font-weight:bold">(</span>bizstatus<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#998;font-style:italic">//是否发布
</span><span style="color:#998;font-style:italic"></span>        String jn29_006 <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_006&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>StringUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">isNotBlank</span><span style="color:#000;font-weight:bold">(</span>jn29_006<span style="color:#000;font-weight:bold">))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and t.jn29_006  = ?  &#34;</span><span style="color:#000;font-weight:bold">);</span>
            params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">add</span><span style="color:#000;font-weight:bold">(</span>jn29_006<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#998;font-style:italic">///////////////////////////创建时间开始/////////////////////////
</span><span style="color:#998;font-style:italic"></span>        SimpleDateFormat sdf <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> SimpleDateFormat<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;yyyy-MM-dd HH:mm:ss&#34;</span><span style="color:#000;font-weight:bold">);</span>
        Date applyS <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDate</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;createDatei&#34;</span><span style="color:#000;font-weight:bold">);</span><span style="color:#998;font-style:italic">// 办结时间开始
</span><span style="color:#998;font-style:italic"></span>        String applyStartTimer <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>applyS <span style="color:#000;font-weight:bold">!=</span> <span style="color:#000;font-weight:bold">null</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
            applyStartTimer <span style="color:#000;font-weight:bold">=</span> sdf<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">format</span><span style="color:#000;font-weight:bold">(</span>applyS<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#998;font-style:italic">//拼接开始时间字段
</span><span style="color:#998;font-style:italic"></span>        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>StringUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">isNotBlank</span><span style="color:#000;font-weight:bold">(</span>applyStartTimer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">trim</span><span style="color:#000;font-weight:bold">()))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and to_char(t.CREATEDATE,&#39;yyyy-MM-dd HH:mm:ss&#39;) &gt;=?&#34;</span><span style="color:#000;font-weight:bold">);</span>
            params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">add</span><span style="color:#000;font-weight:bold">(</span>applyStartTimer<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">trim</span><span style="color:#000;font-weight:bold">());</span>
        <span style="color:#000;font-weight:bold">}</span>

        <span style="color:#998;font-style:italic">///////////////////////////创建时间结束/////////////////////////
</span><span style="color:#998;font-style:italic"></span>        Date applyE1 <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDate</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;createDates&#34;</span><span style="color:#000;font-weight:bold">);</span><span style="color:#998;font-style:italic">// 结束办结时间
</span><span style="color:#998;font-style:italic"></span>        String applyEndTimer1 <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">;</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>applyE1 <span style="color:#000;font-weight:bold">!=</span> <span style="color:#000;font-weight:bold">null</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
            applyEndTimer1 <span style="color:#000;font-weight:bold">=</span> sdf<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">format</span><span style="color:#000;font-weight:bold">(</span>applyE1<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#998;font-style:italic">//拼接结束字段
</span><span style="color:#998;font-style:italic"></span>        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>StringUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">isNotEmpty</span><span style="color:#000;font-weight:bold">(</span>applyEndTimer1<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">trim</span><span style="color:#000;font-weight:bold">())</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">!</span><span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">equals</span><span style="color:#000;font-weight:bold">(</span>applyEndTimer1<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">trim</span><span style="color:#000;font-weight:bold">()))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and to_char(t.CREATEDATE,&#39;yyyy-MM-dd HH:mm:ss&#39;) &lt;=?&#34;</span><span style="color:#000;font-weight:bold">);</span>
            params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">add</span><span style="color:#000;font-weight:bold">(</span>applyEndTimer1<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">trim</span><span style="color:#000;font-weight:bold">());</span>

        <span style="color:#000;font-weight:bold">}</span>

        querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; order by t.createdate desc&#34;</span><span style="color:#000;font-weight:bold">);</span>
        String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;select * from (select rownum as numrow,c.* from (&#34;</span> <span style="color:#000;font-weight:bold">+</span> querySQL <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;)&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34; c where rownum &lt;=&#34;</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#000;font-weight:bold">(</span>page <span style="color:#000;font-weight:bold">*</span> size<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;) where numrow &gt;= &#34;</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#000;font-weight:bold">((</span>page <span style="color:#000;font-weight:bold">-</span> 1<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">*</span> size <span style="color:#000;font-weight:bold">+</span> 1<span style="color:#000;font-weight:bold">);</span>
        List<span style="color:#000;font-weight:bold">&lt;</span>Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;&gt;</span> data <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">query</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span>params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">toArray</span><span style="color:#000;font-weight:bold">(),</span>  <span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">,</span> i<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">-&gt;</span> <span style="color:#000;font-weight:bold">{</span>
            Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> map <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> HashMap<span style="color:#000;font-weight:bold">&lt;&gt;();</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;id&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;id&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_001b&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_001b&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_001a&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_001a&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_002&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_002&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_003&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_003&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_004&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_004&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_005&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_005&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;bizstatus&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;bizstatus&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;createdate&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;createdate&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_006&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;jn29_006&#34;</span><span style="color:#000;font-weight:bold">));</span>
            <span style="color:#000;font-weight:bold">return</span> map<span style="color:#000;font-weight:bold">;</span>
        <span style="color:#000;font-weight:bold">});</span>

        String countSql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;select count(1) cnt from (&#34;</span> <span style="color:#000;font-weight:bold">+</span> querySQL <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;) t&#34;</span><span style="color:#000;font-weight:bold">;</span>
        List<span style="color:#000;font-weight:bold">&lt;</span>Integer<span style="color:#000;font-weight:bold">&gt;</span> cs <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">query</span><span style="color:#000;font-weight:bold">(</span>countSql<span style="color:#000;font-weight:bold">,</span>params<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">toArray</span><span style="color:#000;font-weight:bold">(),</span>  <span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">,</span> i<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">-&gt;</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getInt</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;cnt&#34;</span><span style="color:#000;font-weight:bold">));</span>

        gridData<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;total&#34;</span><span style="color:#000;font-weight:bold">,</span> cs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">get</span><span style="color:#000;font-weight:bold">(</span>0<span style="color:#000;font-weight:bold">));</span>
        gridData<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;page&#34;</span><span style="color:#000;font-weight:bold">,</span> page<span style="color:#000;font-weight:bold">);</span>
        gridData<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;data&#34;</span><span style="color:#000;font-weight:bold">,</span> data<span style="color:#000;font-weight:bold">);</span>

        <span style="color:#000;font-weight:bold">return</span> gridData<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"> <span style="color:#3c5d5d;font-weight:bold">@Override</span>
    <span style="color:#000;font-weight:bold">public</span> HashMap<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">QueryImportPageRCList</span><span style="color:#000;font-weight:bold">(</span>JSONObject jsonObject<span style="color:#000;font-weight:bold">,</span> Integer page<span style="color:#000;font-weight:bold">,</span> Integer size<span style="color:#000;font-weight:bold">,</span> String status<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>

        StringBuffer querySQL <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> StringBuffer<span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;select * from PC_PERSON_TEMP where reviewStatus in (&#34;</span> <span style="color:#000;font-weight:bold">+</span> status <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;) and CREATEUSER = &#39;&#34;</span> <span style="color:#000;font-weight:bold">+</span> currentUserService<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getCurrentUser</span><span style="color:#000;font-weight:bold">().</span><span style="color:#008080">getLogonName</span><span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;&#39; and bizStatus = &#39;1&#39; &#34;</span><span style="color:#000;font-weight:bold">);</span>
        String name <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;name&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>name <span style="color:#000;font-weight:bold">!=</span> <span style="color:#000;font-weight:bold">null</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">!</span><span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">equals</span><span style="color:#000;font-weight:bold">(</span>name<span style="color:#000;font-weight:bold">))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and A01001 like &#39;%&#34;</span> <span style="color:#000;font-weight:bold">+</span> name <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;%&#39;&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        String idNumber <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;idNumber&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>idNumber <span style="color:#000;font-weight:bold">!=</span> <span style="color:#000;font-weight:bold">null</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">!</span><span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">equals</span><span style="color:#000;font-weight:bold">(</span>idNumber<span style="color:#000;font-weight:bold">))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and A01084 like &#39;%&#34;</span> <span style="color:#000;font-weight:bold">+</span> idNumber <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;%&#39;&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        String rckh <span style="color:#000;font-weight:bold">=</span> jsonObject<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;rckh&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">if</span> <span style="color:#000;font-weight:bold">(</span>rckh <span style="color:#000;font-weight:bold">!=</span> <span style="color:#000;font-weight:bold">null</span> <span style="color:#000;font-weight:bold">&amp;&amp;</span> <span style="color:#000;font-weight:bold">!</span><span style="color:#d14">&#34;&#34;</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">equals</span><span style="color:#000;font-weight:bold">(</span>rckh<span style="color:#000;font-weight:bold">))</span> <span style="color:#000;font-weight:bold">{</span>
            querySQL<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">append</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34; and CARDNUMBER like &#39;%&#34;</span> <span style="color:#000;font-weight:bold">+</span> rckh <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;%&#39;&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>

        String sql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;select * from (select rownum as numrow,c.* from (&#34;</span> <span style="color:#000;font-weight:bold">+</span> querySQL <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;)&#34;</span> <span style="color:#000;font-weight:bold">+</span>
                <span style="color:#d14">&#34; c where rownum&lt;=&#34;</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#000;font-weight:bold">(</span>page <span style="color:#000;font-weight:bold">*</span> size<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;) where numrow&gt;=&#34;</span> <span style="color:#000;font-weight:bold">+</span> <span style="color:#000;font-weight:bold">((</span>page <span style="color:#000;font-weight:bold">-</span> 1<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">*</span> size <span style="color:#000;font-weight:bold">+</span> 1<span style="color:#000;font-weight:bold">);</span>
        List<span style="color:#000;font-weight:bold">&lt;</span>Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;&gt;</span> data <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">query</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">,</span> <span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">,</span> i<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">-&gt;</span> <span style="color:#000;font-weight:bold">{</span>
            Map<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> map <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> HashMap<span style="color:#000;font-weight:bold">&lt;&gt;();</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;id&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;ID&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;name&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;A01001&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;idNumber&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;A01084&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;rckh&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;CARDNUMBER&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;rcLevel&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;P31010A&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;gzdw&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;A17015A&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;mobile&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;MOBILE&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;zpId&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;ZPID&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;issw&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;ISSW&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;rdDate&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDate</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;CREATETIME&#34;</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">==</span> <span style="color:#000;font-weight:bold">null</span> <span style="color:#000;font-weight:bold">?</span> <span style="color:#d14">&#34;&#34;</span> <span style="color:#000;font-weight:bold">:</span>
                    DateUtil<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">dateToStr</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDate</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;CREATETIME&#34;</span><span style="color:#000;font-weight:bold">),</span> <span style="color:#d14">&#34;yyyy/MM/dd&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;createUser&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;CREATEUSER&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;status&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getLong</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;REVIEWSTATUS&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;imgSrc&#34;</span><span style="color:#000;font-weight:bold">,</span> url <span style="color:#000;font-weight:bold">+</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;zpuuId&#34;</span><span style="color:#000;font-weight:bold">));</span>
            map<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;pcId&#34;</span><span style="color:#000;font-weight:bold">,</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;PCID&#34;</span><span style="color:#000;font-weight:bold">));</span>
            <span style="color:#000;font-weight:bold">return</span> map<span style="color:#000;font-weight:bold">;</span>
        <span style="color:#000;font-weight:bold">});</span>
        String countSql <span style="color:#000;font-weight:bold">=</span> <span style="color:#d14">&#34;select count(1) cnt from (&#34;</span> <span style="color:#000;font-weight:bold">+</span> querySQL <span style="color:#000;font-weight:bold">+</span> <span style="color:#d14">&#34;) t&#34;</span><span style="color:#000;font-weight:bold">;</span>
        List<span style="color:#000;font-weight:bold">&lt;</span>Integer<span style="color:#000;font-weight:bold">&gt;</span> cs <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">query</span><span style="color:#000;font-weight:bold">(</span>countSql<span style="color:#000;font-weight:bold">,</span> <span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">,</span> i<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">-&gt;</span> rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getInt</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;cnt&#34;</span><span style="color:#000;font-weight:bold">));</span>
        HashMap<span style="color:#000;font-weight:bold">&lt;</span>String<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">&gt;</span> gridData <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> HashMap<span style="color:#000;font-weight:bold">&lt;&gt;();</span>
        gridData<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;total&#34;</span><span style="color:#000;font-weight:bold">,</span> cs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">get</span><span style="color:#000;font-weight:bold">(</span>0<span style="color:#000;font-weight:bold">));</span>
        gridData<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;page&#34;</span><span style="color:#000;font-weight:bold">,</span> page<span style="color:#000;font-weight:bold">);</span>
        gridData<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">put</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;Data&#34;</span><span style="color:#000;font-weight:bold">,</span> data<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">return</span> gridData<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p>$\color{red}{JDBCTemplate的 query 方法用于执行SQL语句，简化JDBC的代码。}$
$\color{red}{同时还可以在SQL语句中使用 ？ 占位，在query 方法的 Object&hellip; args 可变参数中传入对应的参数。}$</p>
<h2 id="jdbctemplate原理">JdbcTemplate原理</h2>
<h3 id="11模拟jdbctemplate">1.1	模拟JdbcTemplate</h3>
<p>  我们看到在使用JdbcTemplate的query方法返回对象，需要用到JdbcTemplate类、RowMapper接口。我们使用代码来模拟JdbcTemplate的query方法。</p>
<h3 id="12步骤分析">1.2	步骤分析</h3>
<p>1 定义MyRowMapper<!-- raw HTML omitted -->接口，模拟RowMapper，添加T mapRow(ResultSet rs)抛出SQLException异常，方法用于处理一行结果。<br>
2 定义MyJdbcTemplate类，模拟JdbcTemplate类的功能<br>
3	在MyJdbcTemplate定义一个构造方法，参数为DataSource<br>
4	在MyJdbcTemplate定义方法</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> List<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">query</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">,</span> MyRowMapper<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> rowMapper<span style="color:#000;font-weight:bold">,</span> Object<span style="color:#000;font-weight:bold">...</span><span style="color:#008080">args</span><span style="color:#000;font-weight:bold">)</span>
</code></pre></td></tr></table>
</div>
</div><p>用于实现查询返回对象集合。在方法中使用JDBC查询数据表，并且调用MyRowMapper接口中的方法将每一行结果封装成一个T对象，添加到List集合中返回list对象。<br>
5	定义测试类，编写SQL语句，使用MyJdbcTemplate的query方法来查询数据。</p>
<div class="highlight"><div style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4">
<table style="border-spacing:0;padding:0;margin:0;border:0;width:auto;overflow:auto;display:block;"><tr><td style="vertical-align:top;padding:0;margin:0;border:0;">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 1
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 2
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 3
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 4
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 5
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 6
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 7
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 8
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f"> 9
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">10
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">11
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">12
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">13
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">14
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">15
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">16
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">17
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">18
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">19
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">20
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">21
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">22
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">23
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">24
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">25
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">26
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">27
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">28
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">29
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">30
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">31
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">32
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">33
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">34
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">35
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">36
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">37
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">38
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">39
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">40
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">41
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">42
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">43
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">44
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">45
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">46
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">47
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">48
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">49
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">50
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">51
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">52
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">53
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">54
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">55
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">56
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">57
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">58
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">59
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">60
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">61
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">62
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">63
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">64
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">65
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">66
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">67
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">68
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">69
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">70
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">71
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">72
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">73
</span><span style="margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">74
</span></code></pre></td>
<td style="vertical-align:top;padding:0;margin:0;border:0;;width:100%">
<pre style="background-color:#fff;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#998;font-style:italic">//定义MyRowMapper&lt;T&gt;接口，模拟RowMapper，用于处理一行结果。
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">interface</span> <span style="color:#458;font-weight:bold">MyRowMapper</span><span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#000;font-weight:bold">{</span>
    T <span style="color:#900;font-weight:bold">mapRow</span><span style="color:#000;font-weight:bold">(</span>ResultSet rs<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">throws</span> SQLException<span style="color:#000;font-weight:bold">;</span>
<span style="color:#000;font-weight:bold">}</span>

<span style="color:#998;font-style:italic">//定义MyJdbcTemplate类，模拟JdbcTemplate类的功能
</span><span style="color:#998;font-style:italic"></span><span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">MyJdbcTemplate</span> <span style="color:#000;font-weight:bold">{</span>

    <span style="color:#000;font-weight:bold">private</span> DataSource ds<span style="color:#000;font-weight:bold">;</span>

    <span style="color:#998;font-style:italic">//在MyJdbcTemplate定义一个构造方法，参数为DataSource
</span><span style="color:#998;font-style:italic"></span>    MyJdbcTemplate<span style="color:#000;font-weight:bold">(</span>DataSource ds<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        <span style="color:#000;font-weight:bold">this</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">ds</span> <span style="color:#000;font-weight:bold">=</span> ds<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>

    <span style="color:#998;font-style:italic">/*
</span><span style="color:#998;font-style:italic">用于实现查询返回对象集合。在方法中使用JDBC查询数据表，
</span><span style="color:#998;font-style:italic">并且调用MyRowMapper接口中的方法将每一行结果封装成一个T对象
</span><span style="color:#998;font-style:italic">添加到List集合中返回list对象。
</span><span style="color:#998;font-style:italic">     */</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> List<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> <span style="color:#900;font-weight:bold">query</span><span style="color:#000;font-weight:bold">(</span>String sql<span style="color:#000;font-weight:bold">,</span> MyRowMapper<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> rowMapper<span style="color:#000;font-weight:bold">,</span> Object <span style="color:#000;font-weight:bold">...</span><span style="color:#008080">args</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        List<span style="color:#000;font-weight:bold">&lt;</span>T<span style="color:#000;font-weight:bold">&gt;</span> list <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> ArrayList<span style="color:#000;font-weight:bold">&lt;&gt;();</span>
        <span style="color:#998;font-style:italic">//从数据源中拿到连接对象
</span><span style="color:#998;font-style:italic"></span>        Connection conn <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">null</span><span style="color:#000;font-weight:bold">;</span>
        PreparedStatement ps <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">null</span><span style="color:#000;font-weight:bold">;</span>
        ResultSet rs <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">null</span><span style="color:#000;font-weight:bold">;</span>
        <span style="color:#000;font-weight:bold">try</span> <span style="color:#000;font-weight:bold">{</span>
            conn <span style="color:#000;font-weight:bold">=</span> ds<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getConnection</span><span style="color:#000;font-weight:bold">();</span>
            ps <span style="color:#000;font-weight:bold">=</span> conn<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">prepareStatement</span><span style="color:#000;font-weight:bold">(</span>sql<span style="color:#000;font-weight:bold">);</span>
            <span style="color:#998;font-style:italic">//使用setXxx来替换占位符
</span><span style="color:#998;font-style:italic"></span>            <span style="color:#000;font-weight:bold">for</span> <span style="color:#000;font-weight:bold">(</span><span style="color:#458;font-weight:bold">int</span> i <span style="color:#000;font-weight:bold">=</span> 0<span style="color:#000;font-weight:bold">;</span> i <span style="color:#000;font-weight:bold">&lt;</span> args<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">length</span><span style="color:#000;font-weight:bold">;</span> i<span style="color:#000;font-weight:bold">++)</span> <span style="color:#000;font-weight:bold">{</span>
                <span style="color:#998;font-style:italic">//替换每个占位符
</span><span style="color:#998;font-style:italic"></span>                ps<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setObject</span><span style="color:#000;font-weight:bold">(</span>i<span style="color:#000;font-weight:bold">+</span>1<span style="color:#000;font-weight:bold">,</span> args<span style="color:#000;font-weight:bold">[</span>i<span style="color:#000;font-weight:bold">]);</span>
            <span style="color:#000;font-weight:bold">}</span>
            rs <span style="color:#000;font-weight:bold">=</span> ps<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">executeQuery</span><span style="color:#000;font-weight:bold">();</span>
            <span style="color:#998;font-style:italic">//封装成List&lt;T&gt;
</span><span style="color:#998;font-style:italic"></span>            <span style="color:#000;font-weight:bold">while</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">next</span><span style="color:#000;font-weight:bold">())</span> <span style="color:#000;font-weight:bold">{</span>
                <span style="color:#998;font-style:italic">//把每条记录封装成一个实体类
</span><span style="color:#998;font-style:italic"></span>                T t <span style="color:#000;font-weight:bold">=</span> rowMapper<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">mapRow</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">);</span>
                list<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">add</span><span style="color:#000;font-weight:bold">(</span>t<span style="color:#000;font-weight:bold">);</span>
            <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">catch</span> <span style="color:#000;font-weight:bold">(</span>SQLException e<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
            e<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">printStackTrace</span><span style="color:#000;font-weight:bold">();</span>
        <span style="color:#000;font-weight:bold">}</span> <span style="color:#000;font-weight:bold">finally</span> <span style="color:#000;font-weight:bold">{</span>
            DataSourceUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">close</span><span style="color:#000;font-weight:bold">(</span>conn<span style="color:#000;font-weight:bold">,</span>ps<span style="color:#000;font-weight:bold">,</span>rs<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#000;font-weight:bold">return</span> list<span style="color:#000;font-weight:bold">;</span>
    <span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">}</span>

<span style="color:#998;font-style:italic">/**
</span><span style="color:#998;font-style:italic">定义测试类，编写SQL语句，使用MyJdbcTemplate的query方法来查询数据。
</span><span style="color:#998;font-style:italic"> */</span>
<span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">class</span> <span style="color:#458;font-weight:bold">Demo09MyTemplate</span> <span style="color:#000;font-weight:bold">{</span>
    <span style="color:#000;font-weight:bold">public</span> <span style="color:#000;font-weight:bold">static</span> <span style="color:#458;font-weight:bold">void</span> <span style="color:#900;font-weight:bold">main</span><span style="color:#000;font-weight:bold">(</span>String<span style="color:#000;font-weight:bold">[]</span> args<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
        MyJdbcTemplate jdbcTemplate <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> MyJdbcTemplate<span style="color:#000;font-weight:bold">(</span>DataSourceUtils<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getDataSource</span><span style="color:#000;font-weight:bold">());</span>
        List<span style="color:#000;font-weight:bold">&lt;</span>User<span style="color:#000;font-weight:bold">&gt;</span> users <span style="color:#000;font-weight:bold">=</span> jdbcTemplate<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">query</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;select * from user where gender=?&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000;font-weight:bold">new</span> MyRowMapper<span style="color:#000;font-weight:bold">&lt;</span>User<span style="color:#000;font-weight:bold">&gt;()</span> <span style="color:#000;font-weight:bold">{</span>
            <span style="color:#3c5d5d;font-weight:bold">@Override</span>
            <span style="color:#000;font-weight:bold">public</span> User <span style="color:#900;font-weight:bold">mapRow</span><span style="color:#000;font-weight:bold">(</span>ResultSet rs<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">throws</span> SQLException <span style="color:#000;font-weight:bold">{</span>
                User user <span style="color:#000;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">new</span> User<span style="color:#000;font-weight:bold">();</span>
                user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setId</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getInt</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;id&#34;</span><span style="color:#000;font-weight:bold">));</span>
                user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setName</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;name&#34;</span><span style="color:#000;font-weight:bold">));</span>
                user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setPassword</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;password&#34;</span><span style="color:#000;font-weight:bold">));</span>
                user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setGender</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;gender&#34;</span><span style="color:#000;font-weight:bold">));</span>
                user<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">setCity</span><span style="color:#000;font-weight:bold">(</span>rs<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">getString</span><span style="color:#000;font-weight:bold">(</span><span style="color:#d14">&#34;city&#34;</span><span style="color:#000;font-weight:bold">));</span>
                <span style="color:#000;font-weight:bold">return</span> user<span style="color:#000;font-weight:bold">;</span>
            <span style="color:#000;font-weight:bold">}</span>
        <span style="color:#000;font-weight:bold">},</span> <span style="color:#d14">&#34;男&#34;</span><span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">for</span> <span style="color:#000;font-weight:bold">(</span>User user <span style="color:#000;font-weight:bold">:</span> users<span style="color:#000;font-weight:bold">)</span> <span style="color:#000;font-weight:bold">{</span>
            System<span style="color:#000;font-weight:bold">.</span><span style="color:#008080">out</span><span style="color:#000;font-weight:bold">.</span><span style="color:#008080">println</span><span style="color:#000;font-weight:bold">(</span>user<span style="color:#000;font-weight:bold">);</span>
        <span style="color:#000;font-weight:bold">}</span>
    <span style="color:#000;font-weight:bold">}</span>

<span style="color:#000;font-weight:bold">}</span>
</code></pre></td></tr></table>
</div>
</div><p><img src="/img/jdbcTemplate.png" alt="alt jdbcTemplate">
<img src="/img/c3p0.png" alt="alt c3p0">
<img src="/img/DRUID.png" alt="alt DRUID">
<img src="/img/jdbcTemplate1.png" alt="alt jdbcTemplate1"></p>

        </div>

        
<div class="post-archive">
    <ul class="post-copyright">
        <li><strong>原文作者：</strong><a rel="author" href="https://laoer123.gitee.io/laoer123">Jeremy Sze</a></li>
        <li style="word-break:break-all"><strong>原文链接：</strong><a href="https://laoer123.gitee.io/laoer123/post/JdbcTemplate%E6%80%BB%E7%BB%93/">https://laoer123.gitee.io/laoer123/post/JdbcTemplate%E6%80%BB%E7%BB%93/</a></li>
        <li><strong>版权声明：</strong>本作品采用<a rel="license" href="https://creativecommons.org/licenses/by-nc-nd/4.0/">知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议</a>进行许可，非商业转载请注明出处（作者，原文链接），商业转载请联系作者获得授权。</li>
    </ul>
</div>
<br/>



        

<div class="post-archive">
    <h2>See Also</h2>
    <ul class="listing">
        
        <li><a href="/laoer123/post/nginx%E5%85%A5%E9%97%A8/">nginx入门</a></li>
        
        <li><a href="/laoer123/post/JWT/">JWT总结</a></li>
        
        <li><a href="/laoer123/post/Rancher_.influxDB_cAdvisor_Grafana/">Rancher_InfluxDB_CAdvisor_Grafana总结</a></li>
        
        <li><a href="/laoer123/post/%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB%E4%B9%8B%E5%89%8D%E7%AB%AF%E6%80%BB%E7%BB%93/">前后分离之前端总结</a></li>
        
        <li><a href="/laoer123/post/Dockerfile%E6%9E%84%E5%BB%BA%E6%9C%8D%E5%8A%A1%E9%95%9C%E5%83%8F%E6%80%BB%E7%BB%93/">Dockerfile构建服务镜像_gogs搭建git_Jenkins持续集成总结</a></li>
        
    </ul>
</div>


        <div class="post-meta meta-tags">
            
            <ul class="clearfix">
                
                <li><a href='https://laoer123.gitee.io/tags/JDBCTemplate'>JDBCTemplate</a></li>
                
            </ul>
            
        </div>
    </article>
    
    <div id="disqus_thread"></div>
<script type="application/javascript">
    var disqus_config = function () {
    
    
    
    };
    (function() {
        if (["localhost", "127.0.0.1"].indexOf(window.location.hostname) != -1) {
            document.getElementById('disqus_thread').innerHTML = 'Disqus comments not available by default when the website is previewed locally.';
            return;
        }
        var d = document, s = d.createElement('script'); s.async = true;
        s.src = '//' + "yourdiscussshortname" + '.disqus.com/embed.js';
        s.setAttribute('data-timestamp', +new Date());
        (d.head || d.body).appendChild(s);
    })();
</script>
<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

    
    
</div>

                </div>

                <div id="secondary">
    <section class="widget">
        <form id="search" action='https://laoer123.gitee.io/laoer123/search/' method="get" accept-charset="utf-8" target="_blank" _lpchecked="1">
      
      <input type="text" name="q" maxlength="20" placeholder="Search">
      <input type="hidden" name="sitesearch" value="https://laoer123.gitee.io/laoer123">
      <button type="submit" class="submit icon-search"></button>
</form>
    </section>
    
    <section class="widget">
        <h3 class="widget-title">最近文章</h3>
<ul class="widget-list">
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/springcloud%E4%B8%8EspringcloudAlibaba%E6%80%BB%E7%BB%93/" title="springcloud与springcloudAlibaba总结">springcloud与springcloudAlibaba总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Seata%E6%80%BB%E7%BB%93/" title="Seata总结">Seata总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/OpenFegin%E6%80%BB%E7%BB%93/" title="OpenFegin总结">OpenFegin总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudGateWay%E6%80%BB%E7%BB%93/" title="SpringCloudGateWay总结">SpringCloudGateWay总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/SpringCloudRibbon/" title="SpringCloudRibbon总结">SpringCloudRibbon总结</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E6%B3%A8%E5%86%8C%E4%B8%8E%E5%8F%91%E7%8E%B0/" title="Nacos配置注册与发现">Nacos配置注册与发现</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E9%85%8D%E7%BD%AE%E7%AE%A1%E7%90%86%E6%BC%94%E7%A4%BA/" title="Nacos配置管理演示">Nacos配置管理演示</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Nacos%E6%80%BB%E7%BB%93/" title="什么是Nacos">什么是Nacos</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%96%B0%E6%89%8B%E6%8C%87%E5%8D%97/" title="Sentinel新手指南">Sentinel新手指南</a>
    </li>
    
    <li>
        <a href="https://laoer123.gitee.io/laoer123/post/Sentinel%E6%8E%A7%E5%88%B6%E5%8F%B0/" title="Sentinel控制台">Sentinel控制台</a>
    </li>
    
</ul>
    </section>

    

    <section class="widget">
        <h3 class="widget-title">分类</h3>
<ul class="widget-list">
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/Linux/">Linux (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/NoSql%E6%95%B0%E6%8D%AE%E5%BA%93/">NoSql数据库 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloud/">SpringCloud (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibaba/">SpringCloudAlibaba (11)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/SpringCloudAlibabaSpringCloud/">SpringCloudAlibaba,SpringCloud (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/docker/">docker (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/java%E5%9F%BA%E7%A1%80/">java基础 (10)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/spring/">spring (4)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E4%BA%8B%E5%8A%A1/">事务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E5%BE%AE%E6%9C%8D%E5%8A%A1/">前端微服务 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E5%89%8D%E7%AB%AF%E6%A1%86%E6%9E%B6/">前端框架 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90/">持续集成 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%90%9C%E7%B4%A2%E5%BC%95%E6%93%8E/">搜索引擎 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%B1%82%E6%A1%86%E6%9E%B6/">数据层框架 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库 (5)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9C%8D%E5%8A%A1%E5%99%A8/">服务器 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%9E%B6%E6%9E%84/">架构 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E6%B6%88%E6%81%AF%E4%B8%AD%E9%97%B4%E4%BB%B6/">消息中间件 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E7%BC%93%E5%AD%98/">缓存 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%AE%A4%E8%AF%81/">认证 (2)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E8%BF%90%E7%BB%B4/">运维 (1)</a></li>
    
    <li><a href="https://laoer123.gitee.io/laoer123/categories/%E9%83%A8%E7%BD%B2/">部署 (1)</a></li>
    
</ul>
    </section>

    <section class="widget">
        <h3 class="widget-title">标签</h3>
<div class="tagcloud">
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Dubbo/">Dubbo</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ES6/">ES6</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElasticSearch/">ElasticSearch</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ElementUI/">ElementUI</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Eureka/">Eureka</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Feign/">Feign</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JDBCTemplate/">JDBCTemplate</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JPA/">JPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/JWT/">JWT</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Jenkins/">Jenkins</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E5%9F%BA%E7%A1%80/">Linux基础</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Linux%E9%85%8D%E7%BD%AE%E8%81%94%E7%BD%91/">Linux配置联网</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/MongoDB/">MongoDB</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Nacos/">Nacos</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/ORACLE/">ORACLE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/OpenFegin/">OpenFegin</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/RabbitMQ/">RabbitMQ</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Seata/">Seata</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/Sentinel/">Sentinel</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudGateWay/">SpringCloudGateWay</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudRibbon/">SpringCloudRibbon</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/SpringCloudSpringCloudAlibaba/">SpringCloud,SpringCloudAlibaba</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/VUE/">VUE</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/docker/">docker</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/git/">git</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/gogs/">gogs</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/hystrix/">hystrix</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/mysql/">mysql</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nginx/">nginx</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/nodeJS/">nodeJS</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/npm/">npm</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springCache/">springCache</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springDataJPA/">springDataJPA</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springboot/">springboot</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudbus/">springcloudbus</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springcloudconfig/">springcloudconfig</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/springdataredis/">springdataredis</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/zuul/">zuul</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F/">分布式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E4%BA%8B%E5%8A%A1/">分布式事务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%88%9B%E5%BB%BA%E6%A8%A1%E5%BC%8F/">创建模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E5%BE%AE%E6%9C%8D%E5%8A%A1/">微服务</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%8E%92%E5%BA%8F/">排序</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E6%9C%8D%E5%8A%A1%E9%95%9C%E5%83%8F%E7%9A%84%E6%9E%84%E5%BB%BA%E4%B8%8E%E9%83%A8%E7%BD%B2/">服务镜像的构建与部署</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E7%BB%93%E6%9E%84%E6%A8%A1%E5%BC%8F/">结构模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%A1%8C%E4%B8%BA%E6%A8%A1%E5%BC%8F/">行为模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">设计模式</a>
    
    <a href="https://laoer123.gitee.io/laoer123/tags/%E8%BF%90%E7%BB%B4/">运维</a>
    
</div>
    </section>

    
<section class="widget">
    <h3 class="widget-title">友情链接</h3>
    <ul class="widget-list">
        
        <li>
            <a target="_blank" href="https://www.cnblogs.com/Jeremy95-Sze/" title="Jeremy Sze的博客">Jeremy Sze的博客</a>
        </li>
        
        <li>
            <a target="_blank" href="https://github.com/Jeremy95-Sze" title="Jeremy Sze的github">Jeremy Sze的github</a>
        </li>
        
    </ul>
</section>


    <section class="widget">
        <h3 class="widget-title">其它</h3>
        <ul class="widget-list">
            <li><a href="https://laoer123.gitee.io/laoer123/index.xml">文章 RSS</a></li>
        </ul>
    </section>
</div>
            </div>
        </div>
    </div>
    <footer id="footer">
    <div class="container">
        &copy; 2023 <a href="https://laoer123.gitee.io/laoer123">Jeremy Sze的博客 By Jeremy Sze</a>.
        Powered by <a rel="nofollow noreferer noopener" href="https://gohugo.io" target="_blank">Hugo</a>.
        <a href="https://www.flysnow.org/" target="_blank">Theme</a> based on <a href="https://github.com/flysnow-org/maupassant-hugo" target="_blank">maupassant</a>.
        
    </div>
</footer>


    
    <script src="//cdnjs.cloudflare.com/ajax/libs/webfont/1.6.28/webfontloader.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/snap.svg/0.5.1/snap.svg-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js" crossorigin="anonymous"></script>
        <script src="//cdnjs.cloudflare.com/ajax/libs/js-sequence-diagrams/1.0.6/sequence-diagram-min.js" crossorigin="anonymous"></script>
        <script>(function () {
            if (!window.Diagram) return;
            const blocks = document.querySelectorAll('pre code.language-sequence');
            for (let i = 0; i < blocks.length; i++) {
                const block = blocks[i];
                
                const rootElement = block.parentNode;
                const container = document.createElement('div');
                const id = `js-sequence-diag-${i}`;
                container.id = id;
                container.className = 'align-center';
                container.setAttribute("style", "overFlow-x:auto");
                rootElement.parentNode.replaceChild(container, rootElement);

                const diagram = Diagram.parse(block.childNodes[0].nodeValue);
                diagram.drawSVG(id, window.sequenceDiagramsOptions
                    ? window.sequenceDiagramsOptions
                    : { theme: 'simple' });
            }
        })();
        </script><script type="text/javascript">
        window.MathJax = {
            tex2jax: {
                inlineMath: [['$', '$']],
                processEscapes: true
                }
            };
    </script>
    <script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML' async></script>


<a id="rocket" href="#top"></a>
<script type="text/javascript" src='/laoer123/js/totop.js?v=0.0.0' async=""></script>

<script type="application/javascript">
var doNotTrack = false;
if (!doNotTrack) {
	window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
	ga('create', 'GA ID', 'auto');
	
	ga('send', 'pageview');
}
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>



    <script type="text/javascript" src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>




    <script src='/laoer123/js/douban.js'></script>

</body>

</html>